﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using COMOSOFT.Class;


namespace COMOSOFT.Production.Forms
{
    public partial class FrmInvoice : Form
    {
        ClassShare cls = new ClassShare("FrmInvoice");
        USC.UscInvoice uscInv = null;
        int InvID;
        public FrmInvoice(int _InvID)
        {
            InitializeComponent();
            this.InvID = _InvID;
        }

        #region [AddNew]


        public void AddNew()
        {
            invoiceMasterBindingSource.AddNew();
        }
        #endregion

        #region [LoadData]
        public void LoadData()
        {
            deliveryMasterTableAdapter.FillBy(dataSet_Delivery.DeliveryMaster);
            if (InvID > 0)
            {
                invoiceMasterTableAdapter.Fill(this.dataSet_Delivery.InvoiceMaster,InvID);
                if (uscInv != null && !uscInv.IsDisposed)
                {
                    uscInv.Select();
                    uscInv.LoadRpt();
                }
                else
                {
                    uscInv = new USC.UscInvoice("rpt_InvLC", InvID);
                    groupControl_InvoiceDetails.Controls.Add(uscInv);
                    uscInv.Dock = DockStyle.Fill;
                    uscInv.LoadRpt();
                    uscInv.Show();
                }
            }
        }
        #endregion
  
        #region[UpdateData]
        public void UpdateInvoice(string com)
        {            
            try
            {
                if (com == "Update")
                {
                    invoiceMasterBindingSource.EndEdit();
                    invoiceMasterTableAdapter.Update(dataSet_Delivery.InvoiceMaster);
                    dataSet_Delivery.InvoiceMaster.AcceptChanges();
                }
                else
                {
                    dataSet_Delivery.InvoiceMaster.Rows[0].Delete();
                    invoiceMasterTableAdapter.Update(dataSet_Delivery.InvoiceMaster);
                    dataSet_Delivery.InvoiceMaster.AcceptChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
        #endregion

        #region[Preview]
        public void Preview()
        {
            if (uscInv != null && !uscInv.IsDisposed)
            {
                uscInv.Select();
                uscInv.LoadRpt();
            }
            else
            {
                uscInv = new USC.UscInvoice("rpt_InvLC",InvID);
                groupControl_InvoiceDetails.Controls.Add(uscInv);
                uscInv.Dock = DockStyle.Fill;
                uscInv.LoadRpt();
                uscInv.Show();
            }
        }
        #endregion
    }
}
